package com.ruoyi.app.dyh.hxf.service.Impl;

import com.ruoyi.app.dyh.hxf.domain.Active;
import com.ruoyi.app.dyh.hxf.domain.Message;
import com.ruoyi.app.dyh.hxf.domain.Organization;
import com.ruoyi.app.dyh.hxf.mapper.MyCreateMapper;
import com.ruoyi.app.dyh.hxf.service.IMessageService;
import com.ruoyi.app.dyh.hxf.service.IMyCreateService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyCreateServiceImpl implements IMyCreateService {

    @Autowired
    private MyCreateMapper myCreateMapper;

    @Autowired
    private MessageServiceImpl messageService;

    /**
     * 创建活动,并发送信息
     * @param active
     * @return
     */
    @Override
    public int insertTeam(Active active) {
        Message message = new Message();
        long userId = SecurityUtils.getLoginUser().getUserId();
        String myName = myCreateMapper.selectMyName(userId);
        message.setCreateBy(myName);
        message.setCreateTime(DateUtils.getNowDate());
        message.setIsDelete("1");
        //根据我的id查询deptId,然后根据deptId到dept表中找到领导人
        // 然后根据领导人找到领导人的id 最后set进去
        long deptId = myCreateMapper.selectDeptId(userId);
        String leaderName = myCreateMapper.selectLeaderName(deptId);
        long lastId = myCreateMapper.selectLastId(leaderName);
        message.setReceiverId(String.valueOf(lastId));
        message.setMgsStatus(1);
        message.setMsgTitle(myName + "创建了活动");
        message.setMsgContent("内容没时间写,等会");
        messageService.insertMessage(message);
        return myCreateMapper.insertTeam(active);
    }

    @Override
    public int insertOrganization(Organization organization) {
        return myCreateMapper.insertOrganization(organization);
    }

    @Override
    public Organization getInfo(String teamId) {
        return myCreateMapper.getInfo(teamId);
    }

    @Override
    public int edit(Organization organization) {
        return myCreateMapper.edit(organization);
    }

    @Override
    public List<String> selectAllId() {
        return myCreateMapper.selectAllId();
    }

    @Override
    public List<Active> selectAllTeam(Long userId) {
        return myCreateMapper.selectAllTeam(userId);
    }
}
